<?php
namespace app\service;
use app\model\MarketModel;

class CurrencyKline
{
    const STATUS_OPEN = 1;
    public static $coins =[];
    public static function  getMarketList()
    {
        $coins = MarketModel::where("status", self::STATUS_OPEN)
            ->field("code")
            ->order("sort", "asc")
            ->column("code");
        self::$coins = arr2lower($coins);
        return self::$coins;
    }
    public static function sub()
    {
        if (empty(self::$coins)) {
            self::getMarketList();
        }
        $sub =[];
        foreach (self::$coins as $key=>$coin) {
            $sub[$key] = sprintf("market.%susdt.kline.1min", $coin);
        }
        return $sub;
    }




    public static  function update($code,$data)
    {
         return   MarketModel::update($data, ['status' =>self::STATUS_OPEN,"code"=>$code]);
    }
}